package models

import (
	"gorm.io/gorm"
	"time"
	"user-srv/basic/inits"
)

// 续费表
type MemberService struct {
	Id        uint64         `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	OrderOr   string         `gorm:"column:order_or;type:varchar(255);comment:续费订单;not null;" json:"order_or"`                                       // 续费订单
	UserId    uint64         `gorm:"column:user_id;type:bigint UNSIGNED;comment:用户id;not null;" json:"user_id"`                                        // 用户id
	LevelId   uint64         `gorm:"column:level_id;type:bigint UNSIGNED;comment:会员id;not null;" json:"level_id"`                                      // 会员id
	Duration  uint32         `gorm:"column:duration;type:int UNSIGNED;comment:续费时长（月）;not null;" json:"duration"`                                   // 续费时长（月）
	Amount    float64        `gorm:"column:amount;type:decimal(10, 2);comment:金额;not null;" json:"amount"`                                             // 金额
	AutoRenew uint8          `gorm:"column:auto_renew;type:tinyint UNSIGNED;comment:是否自动续费 1-不自动 2-自动;not null;default:1;" json:"auto_renew"` // 是否自动续费 1-不自动 2-自动
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// 续费表
func (ms *MemberService) TableName() string {
	return "member_service"
}

// 续费添加
func (ms *MemberService) MemberServiceAdd() error {
	return inits.DB.Create(&ms).Error
}

// 用户选择会员返回价格
func MemberServicePrice(LevelId int) float64 {
	switch LevelId {
	case 1:
		return 9.9
	case 2:
		return 19.9
	case 3:
		return 29.9
	case 4:
		return 39.9
	case 5:
		return 49.9
	default:
		return 9.9
	}
}
